package com.io;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author: csh
 * @Date: 2022/5/31 22:58
 * @Description:  bio流
 */
public class BioServer implements Runnable {
    //端口
    private static int PORT = 8080;
    //服务端
    private static ServerSocket server;

    static ExecutorService executorService = Executors.newCachedThreadPool();

    public static void main(String[] args) throws IOException {
        try {
            server = new ServerSocket(PORT);
            System.out.println("服务器启动成功，等待客户端连接");
            while (true){
                Socket socket = server.accept();
                executorService.submit(new ServerHandler(socket));

            }
        }finally {
            if(server!=null){
                System.out.println("关闭服务器;");
                server.close();
                server = null;
            }
        }
    }

    @Override
    public void run() {
        InputStream in = null;
        OutputStream out = null;
        try {
            byte[] data = new byte[1024];
//            in =
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
